/** @format */
// 自动化生成json文件

const fs = require('fs')
const {cloneDeep} = require('lodash')
const path = require('path')
const {promisify} = require('util')
const writeFile = promisify(fs.writeFile)

const zhCn = require('./zh-cn.js')
// console.log(JSON.stringify(zhCn))

// 测试英文翻译 测试翻译可能不准确
const changeEnUs = obj => {
  for (const key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
      const val = obj[key]
      if (typeof val === 'object') {
        changeEnUs(val)
      } else {
        obj[key] = key === 'name' ? 'English' : key
      }
    }
  }
  return obj
}

const langs = {
  'zh-CN': zhCn.default,
  'en-US': changeEnUs(cloneDeep(zhCn.default)),
  version: new Date().getTime(),
}

writeFile(path.resolve(__dirname, '../langs/langsAll.json'), JSON.stringify(langs))
